/*路由守卫*/
import router from '@/router'
//路由列表
import routerList from '@/assets/utils/routerList';
import state from "@/store/state";
//element 提示框
import {Message} from 'element-ui';
//在跳转之前
router.beforeEach((to, from, next) => {
    //title ico图标
    window.document.title = "代码生产器";
    // let newLink = document.getElementsByTagName('link');
    // newLink[0].outerHTML = "<link rel='shortcut icon' href='https://gd-hbimg.huaban.com/91835998656e77b9d6486f86ec2e98c1ff97b59212df0-xQRcxt_fw658'>"

    // 把权限赋值给vuex
    state.currentPermissions = Number(window.localStorage.getItem('currentPermissions'));
    // 登录页面放行 不在左侧的放行
    if (to.path == '/login' || to.meta.authority.indexOf(0) != -1) {
        next();
        //权限为100的放行  左侧都可以访问
    } else if (to.meta.authority.indexOf(100) != -1) {
        routerList.saveList();
        next();
        //符合权限的放行
    } else if (to.meta.authority.indexOf(Number(window.localStorage.getItem('currentPermissions'))) != -1) {
        routerList.saveList();
        next();
        //不合符权限的限制，并跳转回login页
    } else {
        Message({
            message: '无权限访问',
            type: 'error',
            duration: 3 * 1000
        })
        next('/login');
    }
})

//在跳转之后
router.afterEach(() => {

})
